subroutine decompose(nlog,nxec,nstp,nout)
  use param
  use global
  implicit none
  integer,intent(in) :: nlog,nxec,nstp,nout
  integer :: i,j,k,ng
  real(dbl) :: par_prob,t1
  max_grid=n_rspec
  call check_range(nxec,nstp,rgrid(n_rspec))
  do i=n_rspec,1,-1
     n_split=0
     write(nlog,'(3x,">>>")')
     write(nlog,'(3x,"Decomposing...",1x,i0,"-th..Energy=",1pe9.3)') i,rgrid(i)
     write(*,'(3x,">>>")')
     write(*,'(3x,"Decomposing...",1x,i0,"-th..Energy=",1pe9.3)') i,rgrid(i)
     ncall=0
     call find_next(nlog,nxec,nstp,rgrid(i),next_e,int_n)
     write(nlog,'(3x,"Number of splitting energies..=",i0)') n_split
     write(*,'(3x,"Number of splitting energies..=",i0)') n_split
     if (n_split.lt.2) then
        max_grid=i
        exit
     else
        write(nlog,'(3x,"Original prob=",1pe9.3,1x,"Number of split=",i0,&
                     1x,"Divided prob=",1pe9.3)') rspec(i),n_split,par_prob
        write(*,'(3x,"Original prob=",1pe9.3,1x,"Number of split=",i0,&
                     1x,"Divided prob=",1pe9.3)') rspec(i),n_split,par_prob
        par_prob=res(i)/real(n_split)
        do j=1,n_split
           do k=1,n_rspec
              if (e_split(j).le.egrid(k+1)) then
                 ng=k
                 exit
              end if
           end do
           t1=res(ng)+par_prob
           write(nlog,'(3x,"Energy=",1pe9.3,1x,"Group no.=",i0,1x,"Before=",1pe9.3,1x,"After=",1pe9.3)') &
                rgrid(ng),ng,res(ng),t1
           write(*,'(3x,"Energy=",1pe9.3,1x,"Group no.=",i0,1x,"Before=",1pe9.3,1x,"After=",1pe9.3)') &
                rgrid(ng),ng,res(ng),t1
           res(ng)=t1
        end do
     end if
  end do
  write(nlog,'(3x,"Maximum sub-cascade energy..=",1pe9.3,"(",i0,&
              ")/(Original maximum energy=",1pe9.3,"(",i0,")")') &
              rgrid(max_grid),max_grid,rgrid(n_rspec),n_rspec
  write(*,'(3x,"Maximum sub-cascade energy..=",1pe9.3,"(",i0,&
              ")/(Original maximum energy=",1pe9.3,"(",i0,")")') &
              rgrid(max_grid),max_grid,rgrid(n_rspec),n_rspec
  do i=1,max_grid
     write(nlog,'(3x,"Difference for ",i0,"-th range=",1pe11.5)') i,res(i)-rspec(i)
     write(*,'(3x,"Difference for ",i0,"-th range=",1pe11.5)') i,res(i)-rspec(i)
  end do
end subroutine decompose
